﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;//Please add references
namespace DAL
{
	/// <summary>
	/// 数据访问类:T_WorkTheorySubject02
	/// </summary>
	public partial class T_WorkTheorySubject02
	{
		public T_WorkTheorySubject02()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Model.T_WorkTheorySubject02 model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_WorkTheorySubject02(");
			strSql.Append("WorkTheorySubjectGUID,SubjectID,Title,TypeCode,UserAnswer,StandardAnswer,Score,IsRight,AnswerAnalysis,ClassificationCode,ClassificationName,Knowledge,LevelOfDifficulty,UserScore,EvaluatorCode,EvaluatorName,OrderInf,ExecuteDate,SubjectStatus,ErrorSL,ErrorFruit)");
			strSql.Append(" values (");
			strSql.Append("@WorkTheorySubjectGUID,@SubjectID,@Title,@TypeCode,@UserAnswer,@StandardAnswer,@Score,@IsRight,@AnswerAnalysis,@ClassificationCode,@ClassificationName,@Knowledge,@LevelOfDifficulty,@UserScore,@EvaluatorCode,@EvaluatorName,@OrderInf,@ExecuteDate,@SubjectStatus,@ErrorSL,@ErrorFruit)");
			SqlParameter[] parameters = {
					new SqlParameter("@WorkTheorySubjectGUID", SqlDbType.Char,50),
					new SqlParameter("@SubjectID", SqlDbType.Int,4),
					new SqlParameter("@Title", SqlDbType.NVarChar,500),
					new SqlParameter("@TypeCode", SqlDbType.Int,4),
					new SqlParameter("@UserAnswer", SqlDbType.NVarChar,500),
					new SqlParameter("@StandardAnswer", SqlDbType.NVarChar,500),
					new SqlParameter("@Score", SqlDbType.Float,8),
					new SqlParameter("@IsRight", SqlDbType.Int,4),
					new SqlParameter("@AnswerAnalysis", SqlDbType.NVarChar,500),
					new SqlParameter("@ClassificationCode", SqlDbType.Int,4),
					new SqlParameter("@ClassificationName", SqlDbType.NVarChar,50),
					new SqlParameter("@Knowledge", SqlDbType.NVarChar,50),
					new SqlParameter("@LevelOfDifficulty", SqlDbType.NChar,10),
					new SqlParameter("@UserScore", SqlDbType.Float,8),
					new SqlParameter("@EvaluatorCode", SqlDbType.NVarChar,50),
					new SqlParameter("@EvaluatorName", SqlDbType.NVarChar,50),
					new SqlParameter("@OrderInf", SqlDbType.Int,4),
					new SqlParameter("@ExecuteDate", SqlDbType.VarChar,10),
					new SqlParameter("@SubjectStatus", SqlDbType.Int,4),
					new SqlParameter("@ErrorSL", SqlDbType.Int,4),
					new SqlParameter("@ErrorFruit", SqlDbType.Int,4)};
			parameters[0].Value = model.WorkTheorySubjectGUID;
			parameters[1].Value = model.SubjectID;
			parameters[2].Value = model.Title;
			parameters[3].Value = model.TypeCode;
			parameters[4].Value = model.UserAnswer;
			parameters[5].Value = model.StandardAnswer;
			parameters[6].Value = model.Score;
			parameters[7].Value = model.IsRight;
			parameters[8].Value = model.AnswerAnalysis;
			parameters[9].Value = model.ClassificationCode;
			parameters[10].Value = model.ClassificationName;
			parameters[11].Value = model.Knowledge;
			parameters[12].Value = model.LevelOfDifficulty;
			parameters[13].Value = model.UserScore;
			parameters[14].Value = model.EvaluatorCode;
			parameters[15].Value = model.EvaluatorName;
			parameters[16].Value = model.OrderInf;
			parameters[17].Value = model.ExecuteDate;
			parameters[18].Value = model.SubjectStatus;
			parameters[19].Value = model.ErrorSL;
			parameters[20].Value = model.ErrorFruit;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Model.T_WorkTheorySubject02 model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_WorkTheorySubject02 set ");
			strSql.Append("WorkTheorySubjectGUID=@WorkTheorySubjectGUID,");
			strSql.Append("SubjectID=@SubjectID,");
			strSql.Append("Title=@Title,");
			strSql.Append("TypeCode=@TypeCode,");
			strSql.Append("UserAnswer=@UserAnswer,");
			strSql.Append("StandardAnswer=@StandardAnswer,");
			strSql.Append("Score=@Score,");
			strSql.Append("IsRight=@IsRight,");
			strSql.Append("AnswerAnalysis=@AnswerAnalysis,");
			strSql.Append("ClassificationCode=@ClassificationCode,");
			strSql.Append("ClassificationName=@ClassificationName,");
			strSql.Append("Knowledge=@Knowledge,");
			strSql.Append("LevelOfDifficulty=@LevelOfDifficulty,");
			strSql.Append("UserScore=@UserScore,");
			strSql.Append("EvaluatorCode=@EvaluatorCode,");
			strSql.Append("EvaluatorName=@EvaluatorName,");
			strSql.Append("OrderInf=@OrderInf,");
			strSql.Append("ExecuteDate=@ExecuteDate,");
			strSql.Append("SubjectStatus=@SubjectStatus,");
			strSql.Append("ErrorSL=@ErrorSL,");
			strSql.Append("ErrorFruit=@ErrorFruit");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
					new SqlParameter("@WorkTheorySubjectGUID", SqlDbType.Char,50),
					new SqlParameter("@SubjectID", SqlDbType.Int,4),
					new SqlParameter("@Title", SqlDbType.NVarChar,500),
					new SqlParameter("@TypeCode", SqlDbType.Int,4),
					new SqlParameter("@UserAnswer", SqlDbType.NVarChar,500),
					new SqlParameter("@StandardAnswer", SqlDbType.NVarChar,500),
					new SqlParameter("@Score", SqlDbType.Float,8),
					new SqlParameter("@IsRight", SqlDbType.Int,4),
					new SqlParameter("@AnswerAnalysis", SqlDbType.NVarChar,500),
					new SqlParameter("@ClassificationCode", SqlDbType.Int,4),
					new SqlParameter("@ClassificationName", SqlDbType.NVarChar,50),
					new SqlParameter("@Knowledge", SqlDbType.NVarChar,50),
					new SqlParameter("@LevelOfDifficulty", SqlDbType.NChar,10),
					new SqlParameter("@UserScore", SqlDbType.Float,8),
					new SqlParameter("@EvaluatorCode", SqlDbType.NVarChar,50),
					new SqlParameter("@EvaluatorName", SqlDbType.NVarChar,50),
					new SqlParameter("@OrderInf", SqlDbType.Int,4),
					new SqlParameter("@ExecuteDate", SqlDbType.VarChar,10),
					new SqlParameter("@SubjectStatus", SqlDbType.Int,4),
					new SqlParameter("@ErrorSL", SqlDbType.Int,4),
					new SqlParameter("@ErrorFruit", SqlDbType.Int,4)};
			parameters[0].Value = model.WorkTheorySubjectGUID;
			parameters[1].Value = model.SubjectID;
			parameters[2].Value = model.Title;
			parameters[3].Value = model.TypeCode;
			parameters[4].Value = model.UserAnswer;
			parameters[5].Value = model.StandardAnswer;
			parameters[6].Value = model.Score;
			parameters[7].Value = model.IsRight;
			parameters[8].Value = model.AnswerAnalysis;
			parameters[9].Value = model.ClassificationCode;
			parameters[10].Value = model.ClassificationName;
			parameters[11].Value = model.Knowledge;
			parameters[12].Value = model.LevelOfDifficulty;
			parameters[13].Value = model.UserScore;
			parameters[14].Value = model.EvaluatorCode;
			parameters[15].Value = model.EvaluatorName;
			parameters[16].Value = model.OrderInf;
			parameters[17].Value = model.ExecuteDate;
			parameters[18].Value = model.SubjectStatus;
			parameters[19].Value = model.ErrorSL;
			parameters[20].Value = model.ErrorFruit;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_WorkTheorySubject02 ");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
			};

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_WorkTheorySubject02 GetModel()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 WorkTheorySubjectGUID,SubjectID,Title,TypeCode,UserAnswer,StandardAnswer,Score,IsRight,AnswerAnalysis,ClassificationCode,ClassificationName,Knowledge,LevelOfDifficulty,UserScore,EvaluatorCode,EvaluatorName,OrderInf,ExecuteDate,SubjectStatus,ErrorSL,ErrorFruit from T_WorkTheorySubject02 ");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
			};

			Model.T_WorkTheorySubject02 model=new Model.T_WorkTheorySubject02();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_WorkTheorySubject02 DataRowToModel(DataRow row)
		{
			Model.T_WorkTheorySubject02 model=new Model.T_WorkTheorySubject02();
			if (row != null)
			{
				if(row["WorkTheorySubjectGUID"]!=null)
				{
					model.WorkTheorySubjectGUID=row["WorkTheorySubjectGUID"].ToString();
				}
				if(row["SubjectID"]!=null && row["SubjectID"].ToString()!="")
				{
					model.SubjectID=int.Parse(row["SubjectID"].ToString());
				}
				if(row["Title"]!=null)
				{
					model.Title=row["Title"].ToString();
				}
				if(row["TypeCode"]!=null && row["TypeCode"].ToString()!="")
				{
					model.TypeCode=int.Parse(row["TypeCode"].ToString());
				}
				if(row["UserAnswer"]!=null)
				{
					model.UserAnswer=row["UserAnswer"].ToString();
				}
				if(row["StandardAnswer"]!=null)
				{
					model.StandardAnswer=row["StandardAnswer"].ToString();
				}
				if(row["Score"]!=null && row["Score"].ToString()!="")
				{
					model.Score=decimal.Parse(row["Score"].ToString());
				}
				if(row["IsRight"]!=null && row["IsRight"].ToString()!="")
				{
					model.IsRight=int.Parse(row["IsRight"].ToString());
				}
				if(row["AnswerAnalysis"]!=null)
				{
					model.AnswerAnalysis=row["AnswerAnalysis"].ToString();
				}
				if(row["ClassificationCode"]!=null && row["ClassificationCode"].ToString()!="")
				{
					model.ClassificationCode=int.Parse(row["ClassificationCode"].ToString());
				}
				if(row["ClassificationName"]!=null)
				{
					model.ClassificationName=row["ClassificationName"].ToString();
				}
				if(row["Knowledge"]!=null)
				{
					model.Knowledge=row["Knowledge"].ToString();
				}
				if(row["LevelOfDifficulty"]!=null)
				{
					model.LevelOfDifficulty=row["LevelOfDifficulty"].ToString();
				}
				if(row["UserScore"]!=null && row["UserScore"].ToString()!="")
				{
					model.UserScore=decimal.Parse(row["UserScore"].ToString());
				}
				if(row["EvaluatorCode"]!=null)
				{
					model.EvaluatorCode=row["EvaluatorCode"].ToString();
				}
				if(row["EvaluatorName"]!=null)
				{
					model.EvaluatorName=row["EvaluatorName"].ToString();
				}
				if(row["OrderInf"]!=null && row["OrderInf"].ToString()!="")
				{
					model.OrderInf=int.Parse(row["OrderInf"].ToString());
				}
				if(row["ExecuteDate"]!=null)
				{
					model.ExecuteDate=row["ExecuteDate"].ToString();
				}
				if(row["SubjectStatus"]!=null && row["SubjectStatus"].ToString()!="")
				{
					model.SubjectStatus=int.Parse(row["SubjectStatus"].ToString());
				}
				if(row["ErrorSL"]!=null && row["ErrorSL"].ToString()!="")
				{
					model.ErrorSL=int.Parse(row["ErrorSL"].ToString());
				}
				if(row["ErrorFruit"]!=null && row["ErrorFruit"].ToString()!="")
				{
					model.ErrorFruit=int.Parse(row["ErrorFruit"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select WorkTheorySubjectGUID,SubjectID,Title,TypeCode,UserAnswer,StandardAnswer,Score,IsRight,AnswerAnalysis,ClassificationCode,ClassificationName,Knowledge,LevelOfDifficulty,UserScore,EvaluatorCode,EvaluatorName,OrderInf,ExecuteDate,SubjectStatus,ErrorSL,ErrorFruit ");
			strSql.Append(" FROM T_WorkTheorySubject02 ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" WorkTheorySubjectGUID,SubjectID,Title,TypeCode,UserAnswer,StandardAnswer,Score,IsRight,AnswerAnalysis,ClassificationCode,ClassificationName,Knowledge,LevelOfDifficulty,UserScore,EvaluatorCode,EvaluatorName,OrderInf,ExecuteDate,SubjectStatus,ErrorSL,ErrorFruit ");
			strSql.Append(" FROM T_WorkTheorySubject02 ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_WorkTheorySubject02 ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.WorkTheoryChooseSubjectItemId desc");
			}
			strSql.Append(")AS Row, T.*  from T_WorkTheorySubject02 T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_WorkTheorySubject02";
			parameters[1].Value = "WorkTheoryChooseSubjectItemId";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

